package com.example.controller;

import com.example.pojo.PageResult;
import com.example.pojo.Result;
import com.example.pojo.StuQueryParam;
import com.example.pojo.Student;
import com.example.service.StuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StuController {

    @Autowired
    private StuService stuService;


    @GetMapping
    public Result list(StuQueryParam stuQueryParam) {
        log.info("列表查询学生信息:{}", stuQueryParam);
        PageResult<Student> stuResult = stuService.list(stuQueryParam);
        return Result.success(stuResult);
    }

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        log.info("删除学生信息:{}", ids);
        stuService.delete(ids);
        return Result.success();
    }

    @PostMapping
    public Result insert(@RequestBody Student stu) {
        log.info("添加学生信息:{}", stu);
        stuService.insert(stu);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selectByID(@PathVariable Integer id) {
        log.info("根据id查询学生信息:{}", id);
        Student stu = stuService.selectByID(id);
        return Result.success(stu);

    }


    @PutMapping
    public Result updata(@RequestBody Student stu) {
        log.info("更新员工信息:{}", stu);
        stuService.updata(stu);
        return Result.success();
    }


    @PutMapping("/violation/{id}/{score}")
    public Result DisciplinaryDisposition(
            @PathVariable Integer id,
            @PathVariable Integer score) {
        log.info("违纪处理:{}", id);
        stuService.DisciplinaryDisposition(id, score);
        return Result.success();
    }

}
